<!-- 
  说明：简历编辑依赖的选择组件
 -->
<template>
  <section>
    <div
      :class="['item', { current: ind === index }]"
      v-for="(item, ind) in options"
      :key="ind"
      @click="selectItem(item, ind)"
    >
      {{ item.label }}
    </div>
  </section>
</template>

<script>
import { deepClone } from "../../../../utils";

export default {
  name: "selectCom",
  model: {
    prop: "currentItem",
    event: "change",
  },
  data() {
    return {
      index: 0,
      currentItem: null,
    };
  },
  props: {
    options: {
      type: [Array],
    },
    defaultIndex: {
      type: [Number],
      default: () => {
        return 0;
      },
    },
  },
  mounted() {
    this.index = this.defaultIndex;
  },
  methods: {
    // 选择
    selectItem(item, index) {
      console.log("选项变化>>>", item, index);
      this.index = index;
      this.currentItem = deepClone(item);
      this.$emit("change", this.currentItem.value);
    },
  },
};
</script>

<style lang="less" scoped>
.item {
  position: relative;
  display: inline-block;
  width: 150px;
  height: 52px;
  line-height: 52px;
  text-align: center;
  font-size: 20px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #b0b0b0;
  border: 1px solid #b0b0b0;
  margin-right: 25px;
  border-radius: 5px;
  cursor: pointer;
}
.current {
  color: #4677b9;
  border: 1px solid #4677b9;
}
</style>
